﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NaturalController : MonoBehaviour
{
    public static NaturalController instance;

    private NaturalProp[] naturals;

    private bool isRefresh;

    private float _time;
    // Use this for initialization

    private void Awake()
    {
        instance = this;
    }

    private void OnDestroy()
    {
        instance = null;
    }
    void Start()
    {
        naturals = transform.GetComponentsInChildren<NaturalProp>();
        for (int i = 0; i < naturals.Length; i++)
        {
            naturals[i].index = i;  
        }
        _time = 0;
    }

    // Update is called once per frame
    void Update()
    {
        if (isRefresh == false)
        {
            _time += Time.deltaTime;
            if (_time >= 10)
            {
                _time = 0;  
                for (int i = 0; i < naturals.Length; i++)
                {
                    naturals[i].gameObject.SetActive(true);
                }
                isRefresh = true;   
            }
        }
    }

    public void Refresh(int v)
    {
        StartCoroutine(InRefresh(v));
    }

    IEnumerator InRefresh(int v)
    {
        yield return new WaitForSeconds(10);
        naturals[v].gameObject.SetActive(true);
    }
}

